/*
 * Description: process monitor dll injector
 */
#ifndef PROCESS_MONITOR_INJECTOR_H
#define PROCESS_MONITOR_INJECTOR_H
#include <iostream>
#include <vector>
#include <Windows.h>
#include "singleton.h"
#include <atomic>
#include <mutex>

namespace PERF {

constexpr auto PROCESS_SIZE = 1;
constexpr auto PROCESS_NAME_MAX_LENGTH = 50;
constexpr auto MILLIS_PER_SECOND = 1000L;
constexpr auto CHECK_SECONDS = 60;
constexpr auto INITIALIZE_CHECK_SECONDS = 5;

class ProcessMonitorInjector {
public:
    ProcessMonitorInjector();
    void DetectAndInject();
    bool Uninject();

private:
    void DoDetectAndInject();
    bool RemoteThreadInject(DWORD dwPid);
    std::vector<std::string> processNames_;
    std::atomic_bool stopDetecting_{ false };
    DWORD injectedPid_{ 0 };
    std::mutex injectMutex_;
};
#define PROCESS_MONITOR_INJECTOR SingletonNew<PERF::ProcessMonitorInjector>::GetInstance()
}  // namespace PERF
#endif